package com.ssy.lingxi.system.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

/**
* 对象操作工具类
* @author wrc
* @date 2020/5/25
*/
public class ObjectUtil {


    /**
     * 根据对象属性去重
     * @author wrc
     * @date 2020/5/22
     */
    public static  <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
}
